package com.cjx.stars.common;

import com.cjx.stars.constant.FailMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author cjx
 * @description 全局异常处理器
 * @createDate 2024/2/29 13:45
 **/
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(MyException.class)
    public Response<?> handleMyException(MyException e) {
        FailMessage failMessage = e.getFailMessage();
        log.error("自定义异常："+failMessage.getMessage());
        return ResponseUtils.fail(failMessage);
    }


    @ExceptionHandler(RuntimeException.class)
    public Response<?> handleRunException(RuntimeException e) {
        log.error("runtimeException", e);
        return ResponseUtils.fail(FailMessage.ERROR_SYSTEM);
    }

}
